package com.wanmait.hr.service.Impl;

import com.wanmait.hr.mapper.DepartmentMapper;
import com.wanmait.hr.mapper.RegulationsMapper;
import com.wanmait.hr.service.DepartmentService;
import com.wanmait.hr.vo.Department;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * DepartmentServiceImpl class
 *
 * @author 王志斌
 * @date 2019/01/22
 * */

@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Resource
    private DepartmentMapper departmentMapper;
    @Resource
    private RegulationsMapper regulationsMapper;

    @Override
    public List<Department> getDepartment() {
        return departmentMapper.getDepartment();
    }

    @Override
    public Department getDepartmentManager(Integer id) {
        return departmentMapper.getDepartmentManager(id);
    }

    /** 新增部门_获取自增长的id 王志斌
     * @param department
     * @param html
     * */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int departmentInsert(Department department, String html) {

        /**如果部门简介为空给他一个null*/
        if(department.getRemark().equals(""))
        {
            department.setRemark(null);
        }
        int succeedInsert = departmentMapper.departmentInsert(department, html);
        //部门规章制度
        if(html.equals(""))
        {
            html = "部门暂无规章制度";
        }

        regulationsMapper.insertDepartRegulation(html, department.getId(), department.getUpAdmin().getId());

        return succeedInsert;
    }

    /**显示所有部门_王志斌
     * @return Department
     * */
    @Override
    public List<Department> getAllDepartmentList() {
        return departmentMapper.getAllDepartmentList();
    }

    /**根据部门id显示部门备注_王志斌
     * @param departId
     * @return String
     * */
    @Override
    public String departRemark(Integer departId) {
        return departmentMapper.departRemark(departId);
    }

    /**修改部门时根据部门id查询部门信息_王志斌
     * @param departId
     * @return Department
     * */
    @Override
    public Department quartTheDepartById(Integer departId) {
        Department department = departmentMapper.quartTheDepartById(departId);
        if(department.getRemark() == null)
        {
            department.setRemark("");
        }
        return department;
    }

    /**修改部门
     * @param department
     * */
    @Override
    public void updateDepart(Department department) {
        departmentMapper.updateDepart(department);
    }

    /**删除部门_王志斌
     * @param departId
     * */
    @Override
    public void deleteDepart(Integer departId) {
        departmentMapper.deleteDepart(departId);
    }

    /**获取部门总数_王志斌
     * */
    @Override
    public Integer departNum() {
        return departmentMapper.departNum();
    }

    @Override
    public List<Department> findAll() {
        return null;
    }

    @Override
    public List<Department> findAll(Department object) {
        return null;
    }

    @Override
    public Department findById(Integer id) {
        return null;
    }

    @Override
    public void insert(Department object) {

    }

    @Override
    public void update(Department object) {

    }

    @Override
    public void delete(int id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public int getDataCount() {
        return 0;
    }

    @Override
    public int getDataCount(Department object) {
        return 0;
    }
}
